package com.kltn.zigo;

import java.util.ArrayList;
import java.util.HashMap;

import com.android.zing.ZME_Error;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.GoogleMap.OnMyLocationChangeListener;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.kltn.zigo.NearHereActivity.LoadPlaceAsync;
import com.kltn.zigo.data.adapter.CommentPlaceAdapter;
import com.kltn.zigo.data.adapter.GroupCustomerAdapter;
import com.kltn.zigo.data.adapter.PlaceDetailAdapter;
import com.kltn.zigo.data.insert.CommentInsert;
import com.kltn.zigo.data.insert.DetailUtilityPlaceInsert;
import com.kltn.zigo.data.insert.LikeInsert;
import com.kltn.zigo.data.insert.RatingInsert;
import com.kltn.zigo.data.insert.ReportInsert;
import com.kltn.zigo.data.loader.CommentPlaceLoader;
import com.kltn.zigo.data.loader.GroupCustomerLoader;
import com.kltn.zigo.data.loader.PlaceDetailLoader;
import com.kltn.zigo.data.loader.UserLoader;
import com.kltn.zigo.process.ImageLoader;
import com.kltn.zigo.zingme.sdk.BaseRequestListener;
import com.kltn.zigo.zingme.sdk.ZingMeSDK;

import android.location.Location;
import android.os.AsyncTask;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.app.FragmentActivity;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RatingBar;
import android.widget.Toast;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class PlaceDetailActivity extends FragmentActivity implements OnClickListener{
	
	//ViewFlipper vflipper;
	//Button btnNext;
	//Button btnPrevious;
	// Progress Dialog
	private ProgressDialog pDialog;
    private HashMap<String, String> place;
	PlaceDetailAdapter adapter;	
	
	CommentPlaceAdapter commentplaceAdapter;
	ArrayList<HashMap<String, String>> commentList;
	
	HashMap<String, String> userClicked;
	
    private static LayoutInflater inflater=null;
    
    private MenuItem btnMenu;
    private MenuItem btnSearch;
    private MenuItem btnProfile;
	
	 TextView place_id;
     TextView place_name;
     TextView address;
     TextView phone;    
     TextView fax; 
     TextView email;       
     TextView website;
     TextView opentime;
     TextView closetime;
     TextView lowestprice;
     TextView hightestprice;     
     TextView utility;    
     TextView spaceplace;   
     TextView groupcus;
     TextView description;                            
     ImageView thumb_image;
     ImageLoader imageLoader; 
     LinearLayout layNumberPhoneFax;
     LinearLayout layTime;
     LinearLayout layPrice;
     
     String placeid;
     String userid;
	 String username;
	 String userdisplayname;
	 String useravatarurl;
	 String detailcomment;
	 
	 String userIdClicked = "";
	 String usernameClicked = "";
	 String userdisplaynameClicked = "";
	 String useravatarClicked = "";
	 String Url_avatar;
     
     Button btnComment;
     Button btnLike;
     Button btnReport;
     Button btnRating;
     Button btnEdit;
     Button btnCheckIn;
     
     ListView listComment;
     EditText edtPostComment;
     Button btnPostComment;     
     public static boolean taskLoadUserClickedFinished = false;
     int PointRating = 0;

     private GoogleMap googleMap;

	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_place_detail);
		ActionBar actionBar = getActionBar();		
		actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#b51d21")));
		//vflipper = (ViewFlipper) findViewById(R.id.viewFlipper_PlaceDetail);
		
		place_id = (TextView)findViewById(R.id.tvID);
	    place_name = (TextView)findViewById(R.id.tvPlaceName);
	    address = (TextView)findViewById(R.id.tvPlaceAddress); 
	    phone = (TextView)findViewById(R.id.tvPhone);     
	    fax = (TextView)findViewById(R.id.tvFax);    
	    email = (TextView)findViewById(R.id.tvEmail);        
	    website = (TextView)findViewById(R.id.tvWebsite);
	    opentime = (TextView)findViewById(R.id.tvTimeOpen);
	    closetime = (TextView)findViewById(R.id.tvTimeClose);
	    lowestprice = (TextView)findViewById(R.id.tvLowestprice);
	    hightestprice = (TextView)findViewById(R.id.tvHightestprice);     
	    utility = (TextView)findViewById(R.id.tvUtility);     
	    spaceplace = (TextView)findViewById(R.id.tvSpacePlace);    
	    groupcus = (TextView)findViewById(R.id.tvGroupCustomer);  
	    description = (TextView)findViewById(R.id.tvDescription);                                   
	    thumb_image=(ImageView)findViewById(R.id.list_image); 
	    imageLoader=new ImageLoader(getApplicationContext());
	     
	    layNumberPhoneFax = (LinearLayout)findViewById(R.id.layNumberPhoneFax);
	    layTime = (LinearLayout)findViewById(R.id.layTime);
	    layPrice = (LinearLayout)findViewById(R.id.layPrice);
	    
	    btnCheckIn = (Button)findViewById(R.id.btn_check_in);
	    btnComment = (Button)findViewById(R.id.btn_comment);
	    btnEdit = (Button)findViewById(R.id.btn_edit);
	    btnLike = (Button)findViewById(R.id.btn_like);
	    btnRating = (Button)findViewById(R.id.btn_rating);
	    btnReport = (Button)findViewById(R.id.btn_report);
		
		placeid = getIntent().getStringExtra("placeid");
		userid = getIntent().getStringExtra("userid");
		username = getIntent().getStringExtra("username");
		userdisplayname = getIntent().getStringExtra("userdisplayname");
		useravatarurl = getIntent().getStringExtra("useravatarurl");
		
		try {
            // Loading map
            //initilizeMap();
			if (googleMap == null) {
	            googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
	 
	            // check if map is created successfully or not
	            if (googleMap == null) {
	                Toast.makeText(getApplicationContext(),
	                        "Sorry! unable to create maps", Toast.LENGTH_SHORT)
	                        .show();
	            }
	            else
	            {
					
	            	googleMap.setMyLocationEnabled(true); 
	            }
	        }			
 
        } catch (Exception e) {
            e.printStackTrace();
        }
		
		new LoadDetailPlaceAsync().execute();
		
		btnCheckIn.setOnClickListener(this);
		btnComment.setOnClickListener(this);
		btnEdit.setOnClickListener(this);
		btnLike.setOnClickListener(this);
		btnRating.setOnClickListener(this);
		btnReport.setOnClickListener(this);
		
		//btnNext = (Button) findViewById(R.id.btnNext);
		//btnPrevious = (Button) findViewById(R.id.btnPrevious);
		//btnPrevious.setVisibility(View.INVISIBLE);
		
		//btnNext.setOnClickListener(this);
		
		//btnPrevious.setOnClickListener(this);
		
				
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.place_detail, menu);
		btnMenu = menu.findItem(R.id.btn_menu);
		btnSearch = menu.findItem(R.id.btn_search);
		btnProfile = menu.findItem(R.id.btn_profile);
		
		return true;
	}
	
	@Override
	  public boolean onOptionsItemSelected(MenuItem item) {
		 switch (item.getItemId()) {
		   
		    case R.id.btn_profile:
		    {
		    	Intent i=new Intent(getApplicationContext(),ProfileUserActivity.class);
		        i.putExtra("userid", userid);
		        i.putExtra("username", username);
		        i.putExtra("userdisplayname", userdisplayname);
		        i.putExtra("useravatarurl", useravatarurl);
			    startActivity(i);
		    	break;
		    }
		    	
		    case R.id.btn_search:
		    {
		    	Intent i=new Intent(getApplicationContext(),ListPlaceActivity.class);
		    	i.putExtra("userid",userid);
		        i.putExtra("username", username);
		        i.putExtra("userdisplayname", userdisplayname);
		        i.putExtra("useravatarurl", useravatarurl);
			    startActivity(i);
			    break;
		    }
		    
		    case R.id.btn_menu:
		    {
		    	Intent i=new Intent(getApplicationContext(),MainActivity.class);
		        i.putExtra("userid", userid);
		        i.putExtra("username", username);
		        i.putExtra("userdisplayname", userdisplayname);
		        i.putExtra("useravatarurl", useravatarurl);
			    startActivity(i);
		    	break;
		    }
		 }
		 return super.onOptionsItemSelected(item);
	  }
	

	@SuppressLint("NewApi")
	@Override
	public void onClick(View v) {
		switch (v.getId()){
			case R.id.btn_check_in:
			{
				final Dialog dialog = new Dialog(PlaceDetailActivity.this);
                dialog.setContentView(R.layout.dialog_check_in);
                dialog.setTitle("Chia sẻ địa điểm");
                dialog.setCanceledOnTouchOutside(true);
        		btnPostComment = (Button) dialog.findViewById(R.id.btn_Comment);
        		edtPostComment = (EditText) dialog.findViewById(R.id.edt_Comment);
        		
        		final TextView placeNameDialog = (TextView)dialog.findViewById(R.id.tvPlaceName);
        		final TextView addressDialog = (TextView)dialog.findViewById(R.id.tvPlaceAddress);                                    
        		ImageView thumb_image=(ImageView)findViewById(R.id.list_image); 
        		ImageLoader imageLoader=new ImageLoader(getApplicationContext());
        		
        		imageLoader.DisplayImage(Url_avatar , thumb_image);
        		placeNameDialog.setText(place_name.getText().toString());
        		addressDialog.setText(address.getText().toString());
        		
        		btnPostComment.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						detailcomment = edtPostComment.getText().toString().trim();
						new CreateCheckIn().execute();
						dialog.dismiss();
						

						String name = "ZiGo";
						String title = placeNameDialog.getText().toString() + " tại " + addressDialog.getText().toString();
						String description = edtPostComment.getText().toString();
						String urlImg = Url_avatar;
						String titleLink = "http://me.zing.vn/apps/zigo";//Link dia diem
						String actionLink = "https://play.google.com/store/apps/details?id=com.kltn.zigo";		//Link ZiGo		
						String state = String.valueOf(System.currentTimeMillis());				
						ZingMeSDK.getInstance().share(PlaceDetailActivity.this.getApplicationContext(), name, title, description, urlImg, titleLink, actionLink, state, new SocialShareRequestListener(){});
					}
				});
        		
        		dialog.show();
				break;
			}
			case R.id.btn_comment:
			{
				final Dialog dialog = new Dialog(PlaceDetailActivity.this);
                dialog.setContentView(R.layout.dialog_comment);
                dialog.setTitle("Danh sách bình luận");
                dialog.setCanceledOnTouchOutside(true);
                listComment = (ListView)dialog.findViewById(R.id.list_comment);
        		btnPostComment = (Button) dialog.findViewById(R.id.btn_Comment);
        		edtPostComment = (EditText) dialog.findViewById(R.id.edt_Comment);
        		new LoadComment().execute();
        		btnPostComment.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						detailcomment = edtPostComment.getText().toString().trim();
						if(detailcomment.equals(""))
						{
							AlertDialog.Builder alert = new AlertDialog.Builder(PlaceDetailActivity.this);
					    	alert.setTitle("Chú ý");
					    	alert.setMessage("Bạn phải nhập nội dung trong ô bình luận");
					    	alert.setPositiveButton("Ok",
					    	        new DialogInterface.OnClickListener() {
					    	            public void onClick(DialogInterface dialog, int whichButton) {
					    	            }
					    	        });

					    	alert.show();
						}
						else
						{
							new CreateComment().execute();
							edtPostComment.setText("");
							new LoadComment().execute();
						}
					}
				});
        		
        		listComment.setOnItemClickListener(new OnItemClickListener() {
                	@Override
        			public void onItemClick(AdapterView<?> parent, View view,
        					int position, long id) {							
                		View vi=view;
        		        if(view==null)
        		            vi = inflater.inflate(R.layout.item_comment_place, null);

        		        TextView userID = (TextView)vi.findViewById(R.id.tvUserID);
    			        TextView usernametv = (TextView)vi.findViewById(R.id.tvUsername);
    			        TextView displayname = (TextView)vi.findViewById(R.id.tvDisplayname);
    			        TextView urlavatar = (TextView)vi.findViewById(R.id.tvUrlAvatar);
    			        
    			        
    			        userIdClicked = userID.getText().toString();
    			        usernameClicked = usernametv.getText().toString();
    			        userdisplaynameClicked = displayname.getText().toString();
    			        useravatarClicked = urlavatar.getText().toString();
    			        
        		        new LoadUserClicked().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "");
        		            		        
        		        Intent i=new Intent(PlaceDetailActivity.this,ProfileUserActivity.class);
        		        i.putExtra("useridView",userIdClicked);
    			        i.putExtra("usernameView", usernameClicked);
    			        i.putExtra("userdisplaynameView",userdisplaynameClicked);
    			        i.putExtra("useravatarurlView", useravatarClicked);

        		        i.putExtra("userid",userid);
        		        i.putExtra("username", username);
        		        i.putExtra("userdisplayname", userdisplayname);
        		        i.putExtra("useravatarurl", useravatarurl);
        			    startActivity(i);
        	            
        			}
        		});
        		
        		dialog.show();
				break;
			}
			case R.id.btn_edit:
			{
				Intent i=new Intent(PlaceDetailActivity.this,UpdatePlaceActivity.class);
		        i.putExtra("placeid", placeid);
		        i.putExtra("userid",userid);
		        i.putExtra("username", username);
		        i.putExtra("userdisplayname", userdisplayname);
		        i.putExtra("useravatarurl", useravatarurl);
			    startActivity(i);
				break;
			}
			case R.id.btn_like:
			{
				new CreateLike().execute();
				break;
			}
			case R.id.btn_rating:
			{
				final Dialog dialog = new Dialog(PlaceDetailActivity.this);
                dialog.setContentView(R.layout.dialog_rating);
                dialog.setTitle("Đánh giá địa điểm");
                dialog.setCanceledOnTouchOutside(true);
                final String txtPoint = "Điểm: ";
                final TextView tvPoint = (TextView)dialog.findViewById(R.id.tvPoint);
                RatingBar rbPlace = (RatingBar)dialog.findViewById(R.id.ratingBarPlace);
                Button btnOk = (Button)dialog.findViewById(R.id.btn_ok);
                Button btnCancel = (Button)dialog.findViewById(R.id.btn_Cancel);
                
                rbPlace.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
					
					@Override
					public void onRatingChanged(RatingBar ratingBar, float rating,
							boolean fromUser) {
						// TODO Auto-generated method stub
						PointRating = (int) (rating * 2);
						tvPoint.setText(txtPoint + String.valueOf(PointRating));
					}
				});
                
                btnCancel.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						dialog.dismiss();
					}
				});
                
                btnOk.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						new CreateRating().execute();
						dialog.dismiss();
					}
				});
                
                dialog.show();
				break;
			}
			case R.id.btn_report:
			{
				AlertDialog.Builder alert = new AlertDialog.Builder(PlaceDetailActivity.this);
		    	alert.setTitle("Chú ý");
		    	alert.setMessage("Bạn muốn báo cáo xấu địa điểm này?");
		    	alert.setPositiveButton("Ok",
		    	        new DialogInterface.OnClickListener() {
		    	            public void onClick(DialogInterface dialog, int whichButton) {
		    	            	new CreateReport().execute();
		    	            }
		    	        });
		    	alert.setNegativeButton("Cancel",
		    	        new DialogInterface.OnClickListener() {
		    	            public void onClick(DialogInterface dialog, int whichButton) {
		    	            }
		    	        });
		    	alert.show();
				break;
			}
			default: break;
		}
	}
	
	class LoadDetailPlaceAsync extends AsyncTask<String, String, String>
    {
    	PlaceDetailLoader placedetailloader = new PlaceDetailLoader(placeid);
    	@Override
		protected void onPreExecute() {
			super.onPreExecute();
			pDialog = new ProgressDialog(PlaceDetailActivity.this);
			pDialog.setMessage("Loading places. Please wait...");
			pDialog.setIndeterminate(false);
			pDialog.setCancelable(false);
			pDialog.show();
		}
    	
		@Override
		protected String doInBackground(String... params) {
			// TODO Auto-generated method stub
	    	//placeload = new PlaceLoader();
			
			place = placedetailloader.GetPlace();
			return null;
		}
		
		protected void onPostExecute(String file_url) {
			// dismiss the dialog after getting all products
			pDialog.dismiss();
			// updating UI from Background Thread
			runOnUiThread(new Runnable() {
				public void run() {					
			        Url_avatar = place.get(placedetailloader.TAG_URL_AVATAR) + place.get(placedetailloader.TAG_NAME_AVATAR);
			        // Setting all values in listview
			        place_id.setText(place.get(placedetailloader.TAG_PLACE_ID));
			        place_name.setText( place.get(placedetailloader.TAG_PLACE_NAME));
			        
			        if(!place.get(placedetailloader.TAG_DISTRICT_NAME).equals("null") 
			        		&& !place.get(placedetailloader.TAG_DISTRICT_NAME).trim().equals("") 
			        		&& !place.get(placedetailloader.TAG_PROVINCE_NAME).equals("null") 
			        		&& !place.get(placedetailloader.TAG_PROVINCE_NAME).trim().equals(""))	        	
			        	address.setText(Html.fromHtml("<b><u>Địa chỉ:</u></b> " + place.get(placedetailloader.TAG_ADDRESS) 
			        				+ " - " + place.get(placedetailloader.TAG_DISTRICT_NAME) 
			        				+ " - " + place.get(placedetailloader.TAG_PROVINCE_NAME)));
			        else 
			        	if(place.get(placedetailloader.TAG_PROVINCE_NAME).equals("null") 
			        		|| place.get(placedetailloader.TAG_PROVINCE_NAME).trim().equals(""))
			        		address.setText(Html.fromHtml("<b><u>Địa chỉ:</u></b> " + place.get(placedetailloader.TAG_ADDRESS)));
			        else 
			        	if((place.get(placedetailloader.TAG_DISTRICT_NAME).equals("null")
			        		|| place.get(placedetailloader.TAG_DISTRICT_NAME).trim().equals("")) 
			        		&& (!place.get(placedetailloader.TAG_PROVINCE_NAME).equals("null") 
			        			&& !place.get(placedetailloader.TAG_PROVINCE_NAME).trim().equals("")))
				        	address.setText(Html.fromHtml("<b><u>Địa chỉ:</u></b> " + place.get(placedetailloader.TAG_ADDRESS) 
			        				+ " - " + place.get(placedetailloader.TAG_PROVINCE_NAME)));
			        
			        if(place.get(placedetailloader.TAG_PHONE_NUMBER).equals("null") 
			        		|| place.get(placedetailloader.TAG_PHONE_NUMBER).trim().equals(""))
			        	phone.setVisibility(View.GONE);
			        else 
			        	phone.setText(Html.fromHtml("<b><u>SĐT:</u></b> " + place.get(placedetailloader.TAG_PHONE_NUMBER)));
			        
			        if(place.get(placedetailloader.TAG_FAX_NUMBER).equals("null") 
			        		|| place.get(placedetailloader.TAG_FAX_NUMBER).trim().equals(""))
			        	fax.setVisibility(View.GONE);
			        else 
			        	fax.setText(Html.fromHtml("<b><u>Fax:</u></b> " + place.get(placedetailloader.TAG_FAX_NUMBER)));
			        			        
			        if(place.get(placedetailloader.TAG_EMAIL).equals("null")
			        		|| place.get(placedetailloader.TAG_EMAIL).trim().equals(""))
			        	email.setVisibility(View.GONE);
			        else 
			        	email.setText(Html.fromHtml("<b><u>Email:</u></b> " + place.get(placedetailloader.TAG_EMAIL)));

			        if(place.get(placedetailloader.TAG_WEBSITE).equals("null") 
			        		|| place.get(placedetailloader.TAG_WEBSITE).trim().equals(""))
			        	website.setVisibility(View.GONE);
			        else 
			        	website.setText(Html.fromHtml("<b><u>Website:</u></b> " + place.get(placedetailloader.TAG_WEBSITE)));
			        
			        if(place.get(placedetailloader.TAG_OPEN_TIME).equals("null") 
			        		|| place.get(placedetailloader.TAG_OPEN_TIME).trim().equals(""))
			        	opentime.setVisibility(View.GONE);
			        else 
			        	opentime.setText(Html.fromHtml("<b><u>Giờ mở cửa:</u></b> " + place.get(placedetailloader.TAG_OPEN_TIME)));

			        if(place.get(placedetailloader.TAG_CLOSE_TIME).equals("null") 
			        		|| place.get(placedetailloader.TAG_CLOSE_TIME).trim().equals(""))
			        	closetime.setVisibility(View.GONE);
			        else 
			        	closetime.setText(Html.fromHtml("<b><u>Giờ đóng cửa:</u></b> " + place.get(placedetailloader.TAG_CLOSE_TIME)));
			        
			        if(place.get(placedetailloader.TAG_LOWEST_PRICE).equals("null") 
			        		|| place.get(placedetailloader.TAG_LOWEST_PRICE).trim().equals(""))
			        	lowestprice.setVisibility(View.GONE);
			        else 
			        	lowestprice.setText(Html.fromHtml("<b><u>Giá thấp nhất:</u></b> " + place.get(placedetailloader.TAG_LOWEST_PRICE)));
			        
			        if(place.get(placedetailloader.TAG_HIGHTEST_PRICE).equals("null") 
			        		|| place.get(placedetailloader.TAG_HIGHTEST_PRICE).trim().equals(""))
			        	hightestprice.setVisibility(View.GONE);
			        else 
			        	hightestprice.setText(Html.fromHtml("<b><u>Giá cao nhất:</u></b> " + place.get(placedetailloader.TAG_HIGHTEST_PRICE)));

			        if(place.get(placedetailloader.TAG_UTILITY).equals("null") 
			        		|| place.get(placedetailloader.TAG_UTILITY).trim().equals(""))
			        	utility.setVisibility(View.GONE);
			        else 
			        	utility.setText(Html.fromHtml("<b><u>Tiện ích:</u></b> " + place.get(placedetailloader.TAG_UTILITY)));

			        if(place.get(placedetailloader.TAG_SPACE_PLACE).equals("null") 
			        		|| place.get(placedetailloader.TAG_SPACE_PLACE).trim().equals(""))
			        	spaceplace.setVisibility(View.GONE);
			        else 
			        	spaceplace.setText(Html.fromHtml("<b><u>Không gian địa điểm:</u></b> " + place.get(placedetailloader.TAG_SPACE_PLACE)));
		        
			        
			        if(place.get(placedetailloader.TAG_GROUP_CUSTOMER).equals("null") 
			        		|| place.get(placedetailloader.TAG_GROUP_CUSTOMER).trim().equals(""))
			        	groupcus.setVisibility(View.GONE);
			        else 
			        	groupcus.setText(Html.fromHtml("<b><u>Phù hợp với:</u></b> " + place.get(placedetailloader.TAG_GROUP_CUSTOMER)));

			        if(place.get(placedetailloader.TAG_DESCRIPTION).equals("null")
			        		|| place.get(placedetailloader.TAG_DESCRIPTION).trim().equals(""))
			        	description.setVisibility(View.GONE);
			        else 
			        	description.setText(Html.fromHtml("<b><u>Chi tiết thêm:</u></b> " + place.get(placedetailloader.TAG_DESCRIPTION)));
			        
			        imageLoader.DisplayImage(Url_avatar , thumb_image);

			        if(lowestprice.getVisibility() == View.GONE && hightestprice.getVisibility() == View.GONE)
			        	layPrice.setVisibility(View.GONE);
			        if(closetime.getVisibility() == View.GONE && opentime.getVisibility() == View.GONE)
			        	layTime.setVisibility(View.GONE);
			        if(phone.getVisibility() == View.GONE && fax.getVisibility() == View.GONE)
			        	layNumberPhoneFax.setVisibility(View.GONE);
			        
			        MarkerOptions marker = new MarkerOptions()
        			.position(new LatLng(Double.parseDouble(place.get("latitude")), Double.parseDouble(place.get("longitude"))))
					.title(place.get("place_name"))
					.snippet(place.get("address") + "-" + place.get("district_name") + "-" + place.get("province_name"))
					.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker));
        	
        		
						//.title(locPlace.get("place_name"))
						//.snippet(locPlace.get("address") + "-" + locPlace.get("district_name") + "-" + locPlace.get("province_name"))
						
			        Marker mk = googleMap.addMarker(marker);
			        
			        LatLngBounds.Builder builder = new LatLngBounds.Builder();
			        builder.include(mk.getPosition());
			        LatLngBounds bounds = builder.build();
			        int padding = 10; // offset from edges of the map in pixels
			        CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
			        googleMap.moveCamera(cu);
				}
			});

		}
    }
	
	   

    //Load list comment
    class LoadComment  extends AsyncTask<String, String, String>{	  
    	CommentPlaceLoader commentloader = new CommentPlaceLoader(placeid);
	    @Override
	    protected void onPreExecute() {
	    	super.onPreExecute();
	        /*pDialog = new ProgressDialog(PlaceDetailActivity.this);
	        pDialog.setMessage("Loading comment. Please wait...");
	        pDialog.setIndeterminate(false);
	        pDialog.setCancelable(false);
	        pDialog.show();	*/       
	    }
	
		@Override
		protected String doInBackground(String... args) {
			commentList = commentloader.GetCommentPlace();
			return null;
	    }
	
	    //*//**
	    // * After completing background task Dismiss the progress dialog
	    // * **//*
	    protected void onPostExecute(String file_url) {
	    	//pDialog.dismiss();
			// updating UI from Background Thread
			runOnUiThread(new Runnable() {
				public void run() {					
					commentplaceAdapter = new CommentPlaceAdapter(PlaceDetailActivity.this, commentloader, commentList);
					listComment.setAdapter(commentplaceAdapter);				       
				}
			});
	    }
	}
    
    class LoadUserClicked  extends AsyncTask<String, String, String>{	  
    	UserLoader userloader = new UserLoader(userIdClicked);
	    @Override
	    protected void onPreExecute() {
	    	super.onPreExecute();
	        /*pDialog = new ProgressDialog(PlaceDetailActivity.this);
	        pDialog.setMessage("Loading comment. Please wait...");
	        pDialog.setIndeterminate(false);
	        pDialog.setCancelable(false);
	        pDialog.show();	*/       
	    }
	
		@Override
		protected String doInBackground(String... args) {
			userClicked = userloader.GetUser();
			
			return null;
	    }
	
	    //*//**
	    // * After completing background task Dismiss the progress dialog
	    // * **//*
	    protected void onPostExecute(String file_url) {
	    	//pDialog.dismiss();
			// updating UI from Background Thread
			/*runOnUiThread(new Runnable() {
				public void run() {	*/	
	    	useravatarClicked = userClicked.get(userloader.TAG_USER_AVATAR_ZING);
			userdisplaynameClicked = userClicked.get(userloader.TAG_USER_DISPLAY_NAME); 
			usernameClicked = userClicked.get(userloader.TAG_USER_NAME_ZING);
			taskLoadUserClickedFinished = true;
					
			
				/*}
			});*/
	    }
	}
    
    class CreateComment extends AsyncTask<String, String, String> {
    	 
        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            /*pDialog = new ProgressDialog(NewPostActivity.this);
            pDialog.setMessage("Creating DetailUtilityPlace...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();*/
        }
 
        /**
         * Creating place
         * */
        protected String doInBackground(String... args) {
            //String place_name = edtxtPlaceName.getText().toString();
            //String address = edtxtAddress.getText().toString();
        	CommentInsert pc = new CommentInsert(placeid, userid, detailcomment, 1);           
	        pc.InsertComment();
            return null;
        }
   
        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // dismiss the dialog once done
            //pDialog.dismiss();
        } 
    }
    
    class CreateCheckIn extends AsyncTask<String, String, String> {
   	 
        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            /*pDialog = new ProgressDialog(NewPostActivity.this);
            pDialog.setMessage("Creating DetailUtilityPlace...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();*/
        }
 
        /**
         * Creating place
         * */
        protected String doInBackground(String... args) {
            //String place_name = edtxtPlaceName.getText().toString();
            //String address = edtxtAddress.getText().toString();
        	CommentInsert pc = new CommentInsert(placeid, userid, detailcomment, 2);           
	        pc.InsertComment();
            return null;
        }
   
        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // dismiss the dialog once done
            //pDialog.dismiss();
        } 
    }
    
    class CreateLike extends AsyncTask<String, String, String> {
   	 
        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(PlaceDetailActivity.this);
            pDialog.setMessage("Bạn thích địa điểm này!");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }
 
        /**
         * Creating place
         * */
        protected String doInBackground(String... args) {
        	LikeInsert pc = new LikeInsert(placeid, userid);           
	        pc.ConfirmLike();
            return null;
        }
   
        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
        	pDialog.dismiss();
        } 
    }
    
    class CreateReport extends AsyncTask<String, String, String> {
   	 
        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(PlaceDetailActivity.this);
            pDialog.setMessage("Bạn báo cáo xấu địa điểm này!");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }
 
        /**
         * Creating place
         * */
        protected String doInBackground(String... args) {
        	ReportInsert pc = new ReportInsert(placeid, userid);           
	        pc.ConfirmReport();
            return null;
        }
   
        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
        	pDialog.dismiss();
        } 
    }
    
    class CreateRating extends AsyncTask<String, String, String> {
   	 
        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }
 
        /**
         * Creating place
         * */
        protected String doInBackground(String... args) {
        	RatingInsert pc = new RatingInsert(placeid, userid, Integer.toString(PointRating));           
	        pc.InsertRating();
            return null;
        }
   
        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
        } 
    }
	
	public class SocialShareRequestListener extends BaseRequestListener {

		public void onComplete(Object data) {
			// TODO Auto-generated method stub
			final String result = data.toString();
			
			Log.d(TAG, "result social-share=" + result);
			
		}
		
		public void onZmeError(final ZME_Error e){
    		if(e.getErrorCode() == ZME_Error.ZOAUTH_ERR_ACCESSTOKEN_EXPIRED) {
    			ZingMeSDK.getInstance().logout(getApplicationContext());
    		}    		
    	}
	}
}
